//
//  zhuceViewController.m
//  ui豆瓣
//
//  Created by lirui on 15/12/24.
//  Copyright © 2015年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "zhuceViewController.h"
#import "rView.h"

@interface zhuceViewController ()
@property(nonatomic, retain) rView *user1;
@property(nonatomic, retain) UIAlertController *alet;
@end

@implementation zhuceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [ UIColor whiteColor];
    self.navigationItem.title = @"注册";
   self.user1 = [[[NSBundle mainBundle] loadNibNamed:@"rView" owner:self options:nil] firstObject];
    self.user1.center = CGPointMake(self.view.center.x, 200);
    [self.view addSubview:self.user1];
    
   //自定义navigation 按钮(button -> navigationItem)
    UIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 50, 50);
    [button setTitleColor:[ UIColor blackColor] forState:UIControlStateNormal];
    [button setTitle:@"完成" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    UIBarButtonItem *buttonDone = [[ UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = buttonDone;
}
-(void)done
{
    if (self.user1.usertextfield.text.length >0 && self.user1.pwd.text.length > 0 && self.user1.requirepwd.text.length > 0) {
        self.textblock(self.user1.usertextfield.text);
        self.pwdblock (self.user1.pwd.text);
        // NSLog(@"清除");
               NSString *title = NSLocalizedString(@"提示", nil);
        NSString *message = NSLocalizedString(@"注册成功", nil);
        NSString *otherButtonTitle = NSLocalizedString(@"确定", nil);
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
        
        //确认按钮
        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            //NSLog(@"确认");
            [self .navigationController popViewControllerAnimated:YES];
        }];
        
//         //Add the actions.
//        [alertController addAction:cancelAction];
        [alertController addAction:otherAction];
    
        //显示按钮
        [self presentViewController:alertController animated:YES completion:nil];
       
    }
    else
    {  // NSLog(@"清除");
        NSString *title = NSLocalizedString(@"提示", nil);
        NSString *message = NSLocalizedString(@"未注册", nil);
        NSString *cancelButtonTitle = NSLocalizedString(@"取消", nil);
        NSString *otherButtonTitle = NSLocalizedString(@"确定", nil);
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
        
                 //取消按钮.
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    NSLog(@"清除");
                }];
        //确认按钮
        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            NSLog(@"确认");
        }];
        
        //         //Add the actions.
        [alertController addAction:cancelAction];
        [alertController addAction:otherAction];
        
        [self presentViewController:alertController animated:YES completion:nil];

        
    }
    
    }


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
